package gift.justflower.ecp;

import gift.justflower.ecp.bean.User;
import org.nutz.boot.NbApp;
import org.nutz.dao.Dao;
import org.nutz.dao.util.Daos;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Lang;
import org.nutz.mvc.annotation.Ok;

@Ok("json:full")
@IocBean(create = "init", depose = "depose")
public class MainLauncher {

    @Inject
    private PropertiesProxy conf;
    @Inject
    private Dao dao;

    public void init() {
        // NB自身初始化完成后会调用这个方法
        Daos.createTablesInPackage(dao, "gift.justflower.ecp.bean", false);
        Daos.migration(dao, "gift.justflower.ecp.bean", true, true, false);
        if (dao.count(User.class) == 0) {
            User user = new User();
            user.setName("admin");
            user.setPassword(Lang.md5("850823"));
            dao.insert(user);
        }
    }

    public void depose() {
    }

    public static void main(String[] args) throws Exception {
        new NbApp().setArgs(args).setPrintProcDoc(false).run();
    }

}
